#central registry：中央登记中心
#1.route（url）：route决定了url的终结点
#1.1route还有一个重要的参数信息 叫做 options：决定了request和response的method方法【GET,POST,...】,默认为GET
#2.视图函数：用来处理用户的request,并且返回页面数据
#3.返回数据：可以是txt文本，html文件，可以是jsdn文件

from flask import Flask,request
from flask import render_template
from reserch import reserch4letters



app = Flask(__name__)

#1.路由：相对路径，决定了 页面资源 的路径，如果没有登记，将返回404 not found
#1.1 url:相对于：http://127.0.0.1：5000的相对路径
#1.2 methods:[GET] [POST]
#2.视图函数:
#2.1 函数过程决定了你操作的方法（实现的功能），例如 if elief else for while...
#2.2 return:可以是txt文本，html文件(模板渲染)，可以是jsdn文件

#【GET】
@app.route('/',methods=['GET','POST'])
def hello_world():  # put application's code here
    return render_template('hello.html')

@app.route('/index',methods=['GET'])
def index():  # put application's code here
    return render_template('index.html')

@app.route('/index2',methods=['GET'])
def index2():  # put application's code here
    return render_template('index2.html')

@app.route('/hello',methods=['GET'])
def hello():  # put application's code here
    return render_template('hello.html')

@app.route('/study',methods=['GET'])
def study():  # put application's code here
    return render_template('study.html')

@app.route('/shopcar',methods=['GET'])
def shopcar():  # put application's code here
    return render_template('shopcar.html')



#[POST]实现用户输入,点击提交，将数据提交到/result
@app.route('/result',methods=['POST'])
def result():

    py_word = request.form['word']
    py_vowels = request.form['vowels']
    py_found = reserch4letters(py_vowels,py_word)

    return render_template('result.html',
                           found = py_found)

@app.route('/result2',methods=['POST'])
def result2():

    py_firstname = request.form['firstname']
    py_lastname = request.form['lastname']
    py_fullname = py_firstname.title() + ' ' + py_lastname.title()

    return render_template('result2.html',
                           fullname=py_fullname)

@app.route('/shop_result',methods=['POST'])
def shop_result():
    product_lists = [
        ("生日蛋糕", "99元"),
        ("面包", "12元"),
        ("甜甜圈", "9元"),
        ("热狗", "6元"),
        ("烤火鸡", "68元"),
        ("披萨", "48元"),
        ("清蒸鱼", "38元"),
        ("冰淇淋", "9元"),
        ("啤酒","7元")
    ]

    return render_template('shop_result.html',product_lists=product_lists)

@app.route('/menu', methods=['POST', 'GET'])
def menu():



    lst = request.form.getlist('list')
    lst_str = "，".join(lst)
    return render_template('menu.html',
                           lst_name=lst_str)


if __name__ == '__main__':
    app.run()